home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-PPC / SPINLOCK.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  5KB  |  159 lines

  1. #ifndef __ASM_SPINLOCK_H
  2. #define __ASM_SPINLOCK_H
  3.  
  4. #ifndef __SMP__
  5.  
  6. /*
  7.  * Your basic spinlocks, allowing only a single CPU anywhere
  8.  *
  9.  * Gcc-2.7.x has a nasty bug with empty initializers.
  10.  */
  11. #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
  12.   typedef struct { } spinlock_t;
  13.   #define SPIN_LOCK_UNLOCKED (spinlock_t) { }
  14. #else
  15.   typedef struct { int gcc_is_buggy; } spinlock_t;
  16.   #define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 }
  17. #endif
  18.  
  19. #define spin_lock_init(lock)    do { } while(0)
  20. #define spin_lock(lock)        do { } while(0)
  21. #define spin_trylock(lock)    do { } while(0)
  22. #define spin_unlock_wait(lock)    do { } while(0)
  23. #define spin_unlock(lock)    do { } while(0)
  24. #define spin_lock_irq(lock)    cli()
  25. #define spin_unlock_irq(lock)    sti()
  26.  
  27. #define spin_lock_irqsave(lock, flags) \
  28.     do { save_flags(flags); cli(); } while (0)
  29. #define spin_unlock_irqrestore(lock, flags) \
  30.     restore_flags(flags)
  31.  
  32. /*
  33.  * Read-write spinlocks, allowing multiple readers
  34.  * but only one writer.
  35.  *
  36.  * NOTE! it is quite common to have readers in interrupts
  37.  * but no interrupt writers. For those circumstances we
  38.  * can "mix" irq-safe locks - any writer needs to get a
  39.  * irq-safe write-lock, but readers can get non-irqsafe
  40.  * read-locks.
  41.  *
  42.  * Gcc-2.7.x has a nasty bug with empty initializers.
  43.  */
  44. #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
  45.   typedef struct { } rwlock_t;
  46.   #define RW_LOCK_UNLOCKED (rwlock_t) { }
  47. #else
  48.   typedef struct { int gcc_is_buggy; } rwlock_t;
  49.   #define RW_LOCK_UNLOCKED (rwlock_t) { 0 }
  50. #endif
  51.  
  52. #define read_lock(lock)        do { } while(0)
  53. #define read_unlock(lock)    do { } while(0)
  54. #define write_lock(lock)    do { } while(0)
  55. #define write_unlock(lock)    do { } while(0)
  56. #define read_lock_irq(lock)    cli()
  57. #define read_unlock_irq(lock)    sti()
  58. #define write_lock_irq(lock)    cli()
  59. #define write_unlock_irq(lock)    sti()
  60.  
  61. #define read_lock_irqsave(lock, flags)    \
  62.     do { save_flags(flags); cli(); } while (0)
  63. #define read_unlock_irqrestore(lock, flags) \
  64.     restore_flags(flags)
  65. #define write_lock_irqsave(lock, flags)    \
  66.     do { save_flags(flags); cli(); } while (0)
  67. #define write_unlock_irqrestore(lock, flags) \
  68.     restore_flags(flags)
  69.  
  70. #else /* __SMP__ */
  71.  
  72. /* Simple spin lock operations.  There are two variants, one clears IRQ's
  73.  * on the local processor, one does not.
  74.  *
  75.  * We make no fairness assumptions. They have a cost.
  76.  */
  77.  
  78. typedef struct {
  79.     volatile unsigned long lock;
  80.     volatile unsigned long owner_pc;
  81.     volatile unsigned long owner_cpu;
  82. } spinlock_t;
  83.  
  84. #define SPIN_LOCK_UNLOCKED    (spinlock_t) { 0, 0, 0 }
  85. #define spin_lock_init(lp)     do { (lp)->lock = 0; } while(0)
  86. #define spin_unlock_wait(lp)    do { barrier(); } while((lp)->lock)
  87.  
  88. extern void _spin_lock(spinlock_t *lock);
  89. extern void _spin_unlock(spinlock_t *lock);
  90. extern int spin_trylock(spinlock_t *lock);
  91.  
  92. #define spin_lock(lp)            _spin_lock(lp)
  93. #define spin_unlock(lp)            _spin_unlock(lp)
  94.  
  95. #define spin_lock_irq(lock) \
  96.     do { __cli(); spin_lock(lock); } while (0)
  97. #define spin_unlock_irq(lock) \
  98.     do { spin_unlock(lock); __sti(); } while (0)
  99.  
  100. #define spin_lock_irqsave(lock, flags) \
  101.     do { __save_flags(flags); __cli(); spin_lock(lock); } while (0)
  102. #define spin_unlock_irqrestore(lock, flags) \
  103.     do { spin_unlock(lock); __restore_flags(flags); } while (0)
  104.  
  105. extern unsigned long __spin_trylock(volatile unsigned long *lock);
  106.  
  107. /*
  108.  * Read-write spinlocks, allowing multiple readers
  109.  * but only one writer.
  110.  *
  111.  * NOTE! it is quite common to have readers in interrupts
  112.  * but no interrupt writers. For those circumstances we
  113.  * can "mix" irq-safe locks - any writer needs to get a
  114.  * irq-safe write-lock, but readers can get non-irqsafe
  115.  * read-locks.
  116.  */
  117. typedef struct {
  118.     volatile unsigned long lock;
  119.     volatile unsigned long owner_pc;
  120. } rwlock_t;
  121.  
  122. #define RW_LOCK_UNLOCKED (rwlock_t) { 0, 0 }
  123.  
  124. extern void _read_lock(rwlock_t *rw);
  125. extern void _read_unlock(rwlock_t *rw);
  126. extern void _write_lock(rwlock_t *rw);
  127. extern void _write_unlock(rwlock_t *rw);
  128.  
  129. #define read_lock(rw)        _read_lock(rw)
  130. #define write_lock(rw)        _write_lock(rw)
  131. #define write_unlock(rw)    _write_unlock(rw)
  132. #define read_unlock(rw)        _read_unlock(rw)
  133.  
  134. #define read_lock_irq(lock)    do { __cli(); read_lock(lock); } while (0)
  135. #define read_unlock_irq(lock)    do { read_unlock(lock); __sti(); } while (0)
  136. #define write_lock_irq(lock)    do { __cli(); write_lock(lock); } while (0)
  137. #define write_unlock_irq(lock)    do { write_unlock(lock); __sti(); } while (0)
  138.  
  139. #define read_lock_irqsave(lock, flags)    \
  140.     do { __save_flags(flags); __cli(); read_lock(lock); } while (0)
  141. #define read_unlock_irqrestore(lock, flags) \
  142.     do { read_unlock(lock); __restore_flags(flags); } while (0)
  143. #define write_lock_irqsave(lock, flags)    \
  144.     do { __save_flags(flags); __cli(); write_lock(lock); } while (0)
  145. #define write_unlock_irqrestore(lock, flags) \
  146.     do { write_unlock(lock); __restore_flags(flags); } while (0)
  147.  
  148. #endif /* SMP */
  149. #endif /* __ASM_SPINLOCK_H */
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.